package com.zl.csMall.basic.busEnum.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zl.csMall.basic.busEnum.po.BusEnum;
import com.zl.csMall.basic.busEnum.service.BusEnumService;
import com.zl.csMall.basic.busEnum.mapper.BusEnumMapper;
import com.zl.csMall.util.Util;
import org.springframework.stereotype.Service;

/**
 * @description: BusEnumServiceImpl
 * @author: ChenNing
 * @date 2025-10-20 11:36
 */
@Service
public class BusEnumServiceImpl extends ServiceImpl<BusEnumMapper, BusEnum> implements BusEnumService {


    @Override
    public boolean isRepeat(long id, String name) {
        LambdaQueryWrapper<BusEnum> busEnumQuery = new LambdaQueryWrapper<>();
        busEnumQuery.eq(BusEnum::getName, name);
        if (id != 0){
            busEnumQuery.ne(BusEnum::getId, id);
        }
        return this.getBaseMapper().selectCount(busEnumQuery) > 0;
    }

    @Override
    public BusEnum getByName(String name) {
        if (Util.isNullOrEmpty(name)){
            return null;
        }
        LambdaQueryWrapper<BusEnum> busEnumQuery = new LambdaQueryWrapper<>();
        busEnumQuery.eq(BusEnum::getName, name);
        BusEnum busEnum = this.getOne(busEnumQuery, false);
        if (busEnum != null && busEnum.getId() != 0){
            return busEnum;
        }
        return null;
    }

}
